<template>
  <div>
    后台首{{ $store.state.user.username }}
    <el-button @click="handleLogout">退出登录</el-button>
  </div>
</template>
<script setup>
import { showModal, toast } from '@/composables/util.js'
import { logout } from '@/api/manager.js'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'

const router = useRouter()
const store = useStore()
const handleLogout = () => {
  showModal("你确定退出登录吗？").then(res => {
    logout().finally(() => {
      store.dispatch('logout')
      //跳转回登录页
      router.push('/login')
      //提示退出成功
      toast("退出登录成功")
    })
  })
}
</script>